﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

using System.Net;
using System.IO;
using HtmlAgilityPack;
using Excel = Microsoft.Office.Interop.Excel;

namespace WebScraping
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }
        public string GetWebContent(string strLink)
        {
            string strContent = "";
            try
            {
                WebRequest objWebRequest = WebRequest.Create(strLink);
                objWebRequest.Credentials = CredentialCache.DefaultCredentials;
                WebResponse objWebResponse = objWebRequest.GetResponse();
                Stream receiveStream = objWebResponse.GetResponseStream();
                StreamReader readStream = new StreamReader(receiveStream, System.Text.Encoding.UTF8);
                strContent = readStream.ReadToEnd();
                objWebResponse.Close();
                readStream.Close();
            }
            catch (Exception ex)
            {
                return ex.Message;
            }
            return strContent;
        }

        private void btThucHien_Click(object sender, EventArgs e)
        {
            //HtmlAgilityPack.HtmlDocument document = new HtmlAgilityPack.HtmlDocument();
            //document.LoadHtml(GetWebContent (txtWebURL.Text ));
            //HtmlNode divNode = document.DocumentNode.SelectSingleNode("//div[@class='pronounce']");
            //if (divNode != null)
            //    lblResult.Text = divNode.InnerText;
            //else
            //    lblResult.Text = "Không tìm thấy";
            using (WebClient webClient = new WebClient())
            {
                string photourl = "http://r.kelkoo.com/r/no/12085413/100334923/162/162/http%3A%2F%2Fwww.jollyroom.no%2Fmedia%2Fcatalog%2Fproduct%2Fcache%2F5%2Fimage%2F200x200%2F9df78eab33525d08d6e5fb8d27136e95%2F1%2F3%2F138489_1.jpg/R8i4cK4LKSF.G4h1Vyz5UptpU1E3B6l5vcwIb_iyNHQ-";
                webClient.DownloadFile(photourl, Application.StartupPath + "\\hinh.jpeg");
            }
        }
    }
}
